<?php
$student = $data['student'];
$honorArr = explode(',', $student['honor']);
//dump($_ENV);
//dump($data);
function safePhone($phone) {
    return substr($phone, 0, 3) . '***' . substr($phone, 7, 4);
}
function safeEmail($email) {
    return substr($email, 0, 3) . '***' . strstr($email, '@');
}
//第一个是原串,第二个是 部份串
 function endWith($haystack, $needle) {

      $length = strlen($needle);
      if($length == 0)
      {
          return true;
      }
      return (substr($haystack, -$length) === $needle);
 }
?>
<!DOCTYPE html>
<html lang="zhcn">
<head>
    <include file="Common/meta" />
    <title>学生详情 - {$_ENV['site'][0]['title']}</title>
    <include file="Common/link" />
    <style>
        body {
            padding-top: 0;
        }
    </style>
</head>
<body class="bg-gray">
<div class="layout-body">
    <div class="container container-main">
        <section class="box user-box">
            <header class="box-header stu-detail-bg">
                <header class="layout-header header-inline">
                    <h1 class="title">人才主页</h1>
                    <a class="header-back" href="#"><i class="icon icon-left"></i></a>
                </header>
                <div class="avatar-box">
                    <img class="user-avatar" src="{$student['photo']}">
                    <if condition="$company['is_verify'] eq '1'">
                        <img class="user-valid" src="/public/asset/img/valid.png">
                    </if>
                </div>
            </header>
            <div class="box-body">
                <div class="parise">
                    <if condition="$data['is_parise'] eq 0">
                        <a id="parise-student" class="parise-icon" href="#" disabled><i class="icon icon-praise"></i></a>
                        <div id="parise-num" class="parise-num">{$student['parise']}</div>
                        <else />
                        <a id="parise-student" class="parise-icon disabled" href="#"><i class="icon icon-praise"></i></a>
                        <div id="parise-num" class="parise-num">{$student['parise']}</div>
                    </if>
                </div>

                <div class="user-name">{$student['name']}</div>
                <div class="info">{$student['school']} &nbsp;&nbsp;&nbsp; {$student['professional']}</div>

                <if condition="$data['is_like'] eq 0">
                    <div class="like-icon">
                        <a id="like-student" href="#">
                            <img class="like-img" src="/public/asset/img/icon-like.jpg">
                            <div class="like-text">LIKE</div>
                        </a>
                    </div>
                    <else />
                    <div class="like-icon">
                        <a id="like-student" class="disabled" href="#">
                            <img class="like-img" src="/public/asset/img/icon-like.jpg">
                            <div class="like-text">LIKE</div>
                        </a>
                    </div>
                </if>


            </div>
        </section>
        <section class="box box-detail">
            <header class="box-header">
                <h3 class="box-title">个人介绍</h3>
            </header>
            <div class="box-body">
                <empty name="student['desc']">
                    <div class="info">暂无相关介绍</div>
                </empty>
                {$student['desc']}
            </div>
        </section>
        <section class="box box-detail">
            <header class="box-header">
                <h3 class="box-title">联系方式（LIKE后可见）</h3>
            </header>
            <div class="box-body">
                <if condition="$data['is_like'] eq 0">
                    <div class="info"><i class="icon icon-phone"></i> {$student['phone']|safePhone}</div>
                    <div class="info"><i class="icon icon-email"></i> {$student['email']|safeEmail}</div>
                <else />
                    <div class="info"><i class="icon icon-phone"></i> {$student['phone']}</div>
                    <div class="info"><i class="icon icon-email"></i> {$student['email']}</div>
                </if>
            </div>
        </section>
        <section class="box box-detail">
            <header class="box-header">
                <h3 class="box-title">个人作品</h3>
            </header>
            <div class="box-body no-padding">
                <if condition="count($data['production']) eq 0">
                    <h3 class="info">暂无个人作品</h3>
                </if>
                <ul class="list-simple word-list">
                    <foreach name="data['production']" item="production">
                        <li class="list-item">
                            <span class="word-name">{$production['product_name']}</span>
                            <notempty name="production['product_file']">
                                <if condition="$production['product_type'] eq 2">
                                    <a class="view-work" href="{$production['product_file']}" target="_blank"><i class="icon icon-right"></i> </a>
                                <elseif condition="$production['product_type'] eq 0" />
                                    <a class="view-work lightbox-show" href="{$production['product_file']}"><i class="icon icon-right"></i></a>
                                <else />
                                    <a class="view-work" href="{$production['product_file']}" target="_blank"><i class="icon icon-right"></i></a>
                                </if>

                            </notempty>
                        </li>
                    </foreach>
                </ul>
            </div>
        </section>
        <section class="box box-detail">
            <header class="box-header">
                <h3 class="box-title">个人荣誉</h3>
            </header>
            <div class="box-body no-padding">
                <notempty name="student['honor']">
                    <ul class="list-simple">
                        <foreach name="honorArr" item="honor">
                            <li class="list-item">{$honor}</li>
                        </foreach>
                    </ul>
                </notempty>
            </div>
        </section>
        <section class="box box-detail">
            <header class="box-header">
                <div class="box-title">相关人才</div>
            </header>
            <div class="box-body">
                <ul id="relative-user" class="relative-list">
                </ul>
            </div>
        </section>
    </div>
</div>
<div id="like-wrap" class="like-wrap">
    <section class="box box-like">
        <div class="box-body">
            <div><img class="logo" src="/public/asset/img/like-img-text.jpg"> </div>
            <textarea id="like-text" placeholder="输入你想对这位同学说的话（LIKE后，如果学生也LIKE了您，就可以查看该学生的联系方式）" rows="4"></textarea>
            <div id="box-like-login">
                <a class="login-link" href="/company/page/login">登陆后发送</a>
                <a class="register-link" href="/company/page/register">没有账号？立即注册 &gt;</a>
            </div>
            <div id="quick-box">
                <div class="">示例：</div>
                <ul id="quick-list" class="quick-list">
                    <li><a href="#">你很优秀，诚邀您来我们公司工作</a> </li>
                    <li><a href="#">你能力不错，希望您能来我们公司工作</a> </li>
                    <li><a href="#">有兴趣来我们公司吗？</a> </li>
                </ul>
            </div>
            <input id="like-btn" class="login-btn" type="button" value="发送">
        </div><!-- ./box-body -->
    </section>
</div><!-- ./like-wrap -->
<!-- 查看图片弹出框 -->
<div id="lightbox" class="lightbox">
    <img id="lightbox-img" class="lightbox-img" src="/Uploads/2016-08-28/57c24893a6f22.jpg">
</div>
<script>
    var page = {
        userType: '{$_ENV['user']['type']}',
        studentId: '{$student['id']}'
    };
</script>
<include file="Common/script" />
<script>
    // 查看图片附件
    $(document).on('click', '.lightbox-show', function (e) {
        e.preventDefault();

        $('#lightbox-img').attr('src', $(this).attr('href'));
        $('#lightbox').dialog();
    });

    // 企业like学生
    $('#like-student').on('click', function (e) {
        e.preventDefault();
        var $this = $(this);

        eui.alert('只有企业才可以 LIKE 噢~', {
            btn: false
        });
        return; // 由于企业不能登陆，无法LIKE

        if (page.userType !== '' && page.userType !== '2') {
            eui.msg('只有企业才可以LIKE学生');
            return;
        }

        if (page.userType !== '2') {
            $('#login-wrap2').dialog();
            return;
        }

        /*if ($this.hasClass('disabled')) {
            eui.msg('不能重复LiKE');
            return;
        }*/

        if (page.userType === '2') { // 企业已经登陆
            $('#box-like-login').hide();
        }

        $('#like-wrap').dialog();
    });

    $('#like-btn').on('click', function () {
        var value = $('#like-text').val();
        if (!value) {
            eui.msg('请输入内容');
            return;
        }
        $.ajax({
            url: '/company/like/like',
            data: {
                id: page.studentId,
                like_msg: value
            },
            type: 'POST',
            dataType: 'json',
            success: function (obj) {
                eui.msg('发送成功，请耐心等待');

                $('#like-wrap').dialog('hide');

                $('#like-student').addClass('disabled');
            },
            error: function () {
                eui.alert('系统出错');
            }
        })
    });

    // 企业点赞学生
    $('#parise-student').on('click', function (e) {
        e.preventDefault();
        var $this = $(this);

        $.ajax({
            url: '/user/parise',
            data: {
                aim_id: page.studentId,
                aim_type: 1 // 1表示赞学生
            },
            type: 'POST',
            dataType: 'json',
            success: function (obj) {
                if (obj.code === 0) {
                    var $num = $('#parise-num');
                    $num.text((parseInt($num.text()) + 1));
                    $num.parent().addClass('disabled');
                    //eui.alert('操作成功');
                } else {
                    eui.msg(obj.msg);
                }
            },
            error: function () {
                eui.alert('系统出错');
            }
        })

    });

    userAjax(1);

    // 相关人才
    function userAjax(page) {
        $.ajax({
            url: '/user/relev',
            data: {
                page: page,
                pageSize: 4
            },
            dataType: 'json',
            success: function (obj) {
                userView(obj);
            },
            error: function () {
                eui.alert('系统出错');
            }
        });
    }

    function userView(obj) {
        var list = obj.list;
        var $ul = $('#relative-user');
        var html = '';
        for (var i = 0; i < list.length; i++) {
            var user = list[i];
            html += '<li class="list-item">'
                + '<a class="link" href="/user/detail?id=' + user.id + '" tr>'
                + '<img class="image" src="' + user.photo + '">'
                + '<div class="name">' + user.name + '</div>'
                + '</a>'
                + '</li>';
        }
        $ul.empty();
        $ul[0].innerHTML = html;
    }

    // 快速输入
    $('#quick-list').on('click', 'a', function (e) {
        e.preventDefault();

        $('#like-text').val($(this).text());
    });

</script>
</body>
</html>

